<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/">
		<html>
			<body>
				<h2>Stammbaum</h2>
				<table border="1">
					<tr bgcolor="#9acd32">
						<th>ID</th>
						<th>First Name</th>
						<th>Middle Name</th>
						<th>Last Name</th>
						<th>Birthday</th>
						<th>Gender</th>
						<th>Father</th>
						<th>Mother</th>
						<th>Marriage</th>
					</tr>
					<xsl:for-each select="stammbaum/person">
						<tr>
							<td>
								<xsl:value-of select="id" />
							</td>
							<td>
								<xsl:value-of select="first_name" />
							</td>
							<td>
								<xsl:for-each select="middle_name">
									<xsl:value-of select="." />
									<br />
								</xsl:for-each>
							</td>
							<td>
								<xsl:value-of select="last_name" />
							</td>
							<td>
								<xsl:value-of select="birthday" />
							</td>
							<td>
								<xsl:value-of select="gender" />
							</td>
							<td>
								<xsl:variable name="vater">
									<xsl:value-of select="father" />
								</xsl:variable>

								<xsl:for-each select="/stammbaum/person">

									<xsl:if test="id=$vater">
										<xsl:value-of select="first_name" />
										<br />
										<xsl:value-of select="last_name" />
									</xsl:if>
								</xsl:for-each>
							</td>
							<td>
								<xsl:variable name="mutter">
									<xsl:value-of select="mother" />
								</xsl:variable>

								<xsl:for-each select="/stammbaum/person">

									<xsl:if test="id=$mutter">
										<xsl:value-of select="first_name" />
										<br />
										<xsl:value-of select="last_name" />
									</xsl:if>
								</xsl:for-each>
							</td>
							<td>
								<xsl:variable name="heirat">
									<xsl:value-of select="marriage" />
								</xsl:variable>

								<xsl:for-each select="marriage">
									<xsl:for-each select="/stammbaum/person">
										<xsl:if test="id=$heirat">
											<xsl:value-of select="first_name" />
											<br />
											<xsl:value-of select="last_name" />
										</xsl:if>
									</xsl:for-each>
								</xsl:for-each>
							</td>
						</tr>
					</xsl:for-each>
				</table>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>